"""
@Project ：Python_Learning 
@File    ：28.找出字符串中第一个匹配项的下表.py
@IDE     ：PyCharm 
@Author  ：zhupp
@Date    ：2024/10/16 13:07 
"""

# class Solution:
#     def strStr(self, haystack: str, needle: str) -> int:
#         needle_len = len(needle)
#         haystack_len = len(haystack)
#         if haystack == needle:
#             return 0
#         if needle_len == 1:
#             for i in haystack:
#                 if i == needle:
#                     return haystack.index(i)
#         for i in range(haystack_len - needle_len + 1):
#             if haystack[i:(i + needle_len)] == needle:
#                 print(haystack[i:(i + needle_len)])
#                 return i
#             print(haystack[i:(i + needle_len)])
#         return -1
#
# s = Solution()
# print(s.strStr("mississippi", "pi"))

def find_str_index(str_long, str_target):
    for i in range(len(str_long)):
        index_start = i
        index_end = i + len(str_target) - 1
        if index_end <= len(str_long) - 1 and str_target == str_long[index_start:index_end + 1]:
            return index_start
    return -1

print(find_str_index("a", "a"))